<template>
  <el-dialog
    title="驳回原因"
    class="gl_dialog_TitleLine gl_dl_footer"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    width="730px"
  >
    <el-form ref="ruleForm" class="gl_form_mini" :model="ApproveDuanExamRequestInput" style="padding: 0 30px" :rules="ruleForm" label-width="130px">
      <div>
        <div>
          <el-form-item label="请输入驳回原因" prop="approveComment">
            <el-input
              v-model="ApproveDuanExamRequestInput.approveComment"
              :disabled="btn"
              type="textarea"
              placeholder="请输入内容"
              show-word-limit
              :rows="3"
            />
          </el-form-item>
        </div>
      </div>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" :disabled="btn" :loading="submitLoading" size="mini" @click="submit('ruleForm')">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { api_PUT_ClubDuanExamRequestIdApprove } from '@/extend/api/hallswaggerApi/app.js';
import { ApproveDuanExamRequestInput } from '@/lib/form/hall/swaggerForm';
export default {
  data() {
    return {
      btn: false,
      submitLoading: false,
      ApproveDuanExamRequestInput: new ApproveDuanExamRequestInput(), // 级段位申请
      dialogVisible: false,
      ruleForm: {
        approveComment: [
          { required: true, message: '请输入驳回原因', trigger: 'blur' }
        ]
      }
    };
  },
  watch: {
    dialogVisible: {
      deep: true,
      handler(val) {
        if (!val) {
          this.$refs['ruleForm'].resetFields();
          this.ApproveDuanExamRequestInput = new ApproveDuanExamRequestInput();
        }
      }
    }
  },
  methods: {
    submit(formName) {
      this.submitLoading = true;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.ApproveDuanExamRequestInput.isApproved = false;
          api_PUT_ClubDuanExamRequestIdApprove(this.$route.query.id, this.ApproveDuanExamRequestInput).then(res => {
            this.submitLoading = false;
            this.$message({
              type: 'success',
              message: '驳回成功'
            });
            this.$router.push({ name: 'Maintenance' });
          }, error => {
            this.submitLoading = false;
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        } else {
          this.submitLoading = false;
          this.$message('请输入驳回原因');
          return false;
        }
      });
    }
  }
};
</script>

<style scoped>
.up_button {
  display: flex;
height: 40px;
align-items: center;
}
.up_button>div {
  margin-right: 16px;
}
</style>
